﻿namespace Gonte.Workflow.Tasks
{
    public class Equal
        : TypedTask
    {
        #region Constructors

        public Equal()
        {
            Type = "Equal";
        } 

        #endregion

        #region ITask Members

        public override TaskResult Execute(TaskContext context)
        {
            ExceptionThrower.ThrowWhenNull("Left", _left);
            ExceptionThrower.ThrowWhenNull("Right", _right);

            TaskResult result = new TaskResult();

            TaskResult leftHandResult = _left.Execute(context);
            TaskResult rightHandResult = _right.Execute(context);

            if (leftHandResult.CompareTo(rightHandResult) == 0)
            {
                result.Value = true;
            }
            else
            {
                result.Value = false;
            }

            return result;
        }

        #endregion

        #region Properties

        public ITask Left
        {
            get { return _left; }
            set { _left = value; }
        }

        public ITask Right
        {
            get { return _right; }
            set { _right = value; }
        } 

        #endregion

        #region Fields

        private ITask _left;
        private ITask _right; 

        #endregion
    }
}
